package com.gis507.test.AISTest4;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * 1、继承Mapper
 * 2、设置输入输出类型
 * 3、重写map方法
 */
public class AISDataMapper extends Mapper<LongWritable,Text, Text,AISDataBean> {

    private Text outK = new Text();
    private AISDataBean outV = new AISDataBean();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {

        //1、获取一行
        String line = value.toString();

        //2、按照“，”分割
        String[] comment = line.split(",");

        //3、取出数组中的数值
        //speed，unixTime，lon_d，lat_d，(String)draught(类型),Length,Width,CallSign,Heading,Course,Rot
        String mmsi = comment[0];

        double speed = Double.parseDouble(comment[1]);
        long unixTime = Long.parseLong(comment[2]);
        double lon_d = Double.parseDouble(comment[3]);
        double lat_d = Double.parseDouble(comment[4]);
        String draught = comment[5];
        String length = comment[6];
        String width = comment[7];
        String callSign = comment[8];
//        double heading = Double.parseDouble(comment[9]);
        double course = Double.parseDouble(comment[10]);
        double rot = Double.parseDouble(comment[11]);

        //4、封装
        outK.set(mmsi);

        outV.setSpeed(speed);
        outV.setUnixTime(unixTime);
        outV.setLon_d(lon_d);
        outV.setLat_d(lat_d);
        outV.setDraught(draught);
        outV.setLength(length);
        outV.setWidth(width);
        outV.setCallsign(callSign);
//        outV.setHeading(heading);
        outV.setCourse(course);
        outV.setRot(rot);

        //5、写出
        context.write(outK,outV);
    }
}
